package org.za.communication.message;

import java.nio.charset.Charset;
import org.apache.http.message.BasicTokenIterator;
import org.apache.mina.core.buffer.IoBuffer;

public class TextMessage extends BaseMessage{
	private byte[] key = new byte[4];
	private String sender;//发送者
	private String receiver;//接收者
	private String messagecontent;//消息内容
	
	public TextMessage() {
		super();
		this.msgId = 0x06;
	}
	

	public byte[] getKey() {
		return key;
	}

	public void setKey(byte[] key) {
		this.key = key;
	}

	public String getSender() {
		return sender;
	}

	public void setSender(String sender) {
		this.sender = sender;
	}

	public String getReceiver() {
		return receiver;
	}

	public void setReceiver(String receiver) {
		this.receiver = receiver;
	}

	public String getMessagecontent() {
		return messagecontent;
	}

	public void setMessagecontent(String messagecontent) {
		this.messagecontent = messagecontent;
	}

	@Override
	public IoBuffer getData() {
		try {
			buf = IoBuffer.allocate(2).setAutoExpand(true);
			buf.putUnsignedShort(this.getMsgId());
			buf.put(key);
			buf.putString(sender, Charset.forName("utf-8").newEncoder());
			buf.put(new byte[1]);
			buf.putString(receiver, Charset.forName("utf-8").newEncoder());
			buf.put(new byte[1]);
			buf.putString(messagecontent, Charset.forName("utf-8").newEncoder());
			buf.put(new byte[1]);
			buf.flip();
			return buf;
		} catch (Exception ee) {
			return null;
		}

		
	}

	@Override
	public void setData(IoBuffer buf) {
		// TODO Auto-generated method stub
		
	}
	

}
